package frog.lazy.framework.keeper.reaml;


import frog.lazy.framework.keeper.dto.AccountDTO;
import frog.lazy.framework.keeper.dto.JwtTokenDTO;
import frog.lazy.framework.keeper.matcher.JwtMatcher;
import frog.lazy.framework.keeper.matcher.PasswordMatcher;
import lombok.AllArgsConstructor;
import org.apache.shiro.realm.Realm;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;


@Component
@AllArgsConstructor
public class RealmManager {

    public List<Realm> initGetRealm() {
        List<Realm> realmList = new LinkedList<>();
        // ----- password
        PasswordRealm passwordRealm = new PasswordRealm();
        passwordRealm.setCredentialsMatcher(new PasswordMatcher());
        passwordRealm.setAuthenticationTokenClass(AccountDTO.class);
        realmList.add(passwordRealm);

        // ----- jwt
        JwtRealm jwtRealm = new JwtRealm();
        jwtRealm.setCredentialsMatcher(new JwtMatcher());
        jwtRealm.setAuthenticationTokenClass(JwtTokenDTO.class);
        realmList.add(jwtRealm);
        return Collections.unmodifiableList(realmList);
    }
}
